package com.lx.api.weight;

import com.lx.core.weight.entity.vo.PriceLastFiveYearGoodsVO;
import com.lx.core.weight.entity.vo.WeightLastFiveYearGoodsVO;
import com.lx.core.weight.service.WeightService;
import com.lx.framework.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lx
 * @date 2025/10/23 16:48
 **/
@RestController
@Api(tags = "称重管理")
@RequestMapping("/weight/statistic")
public class StatisticController {

    private final WeightService weightService;

    public StatisticController(WeightService weightService) {
        this.weightService = weightService;
    }

    @ApiOperation(value = "获取近五年某一类商品得平均价")
    @RequestMapping(value = "/getPastFiveYearGoodsTypePrice", method = RequestMethod.GET)
    public R getPastFiveYearGoodsTypePrice(@RequestParam(name = "goodsType") int goodsType, @RequestParam(name = "dateType") int dateType) {
        List<PriceLastFiveYearGoodsVO> priceLastSevenGoodsVO = new ArrayList<>();
        if (dateType == 2) {
            priceLastSevenGoodsVO = this.weightService.getPastFiveYearGoodsTypePriceByWeek(goodsType);
        } else if (dateType == 3) {
            priceLastSevenGoodsVO = this.weightService.getPastFiveYearGoodsTypePriceByMonth(goodsType);
        } else {
            priceLastSevenGoodsVO = this.weightService.getPastFiveYearGoodsTypePriceByDay(goodsType);
        }
        return R.success("操作成功", priceLastSevenGoodsVO);
    }

    @ApiOperation(value = "获取近五年某一类商品得货物总重量")
    @RequestMapping(value = "/getPastFiveYearGoodsTypeWeight", method = RequestMethod.GET)
    public R getPastFiveYearGoodsTypeWeight(@RequestParam(name = "goodsType") int goodsType, @RequestParam(name = "dateType") int dateType) {
        List<WeightLastFiveYearGoodsVO> weightLastFiveYearGoodsVOS = new ArrayList<>();
        if (dateType == 2) {
            weightLastFiveYearGoodsVOS = this.weightService.getPastFiveYearGoodsTypeWeightByWeek(goodsType);
        } else if (dateType == 3) {
            weightLastFiveYearGoodsVOS = this.weightService.getPastFiveYearGoodsTypeWeightByMonth(goodsType);
        } else {
            weightLastFiveYearGoodsVOS = this.weightService.getPastFiveYearGoodsTypeWeightByDay(goodsType);
        }
        return R.success("操作成功", weightLastFiveYearGoodsVOS);
    }
}
